﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BIExtAuth.Common;

namespace BIExtAuth.Web.Admin.ASHX
{
    /// <summary>
    /// ClassName：解密密码类
    /// Author：scc-john
    /// CreateDate：2014-03-23
    /// </summary>
    public class DecryptionPwd : IHttpHandler
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context">HTTP上下文</param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string pwd = context.Request.Params["pwd"];
            string dePwd = string.Empty;
            var ret = default(object);
            string json = string.Empty;
            try
            {
                dePwd = SecurityEncrypt.DesDecrypt(pwd);
                ret = new { IsTrue = true, DePwd = dePwd };
                json = JSONHelper.ObjectToJSON(ret);
                context.Response.Write(json);
            }
            catch (Exception ex)
            {
                ret = new { IsTrue = false, DePwd = ex.Message };
                json = JSONHelper.ObjectToJSON(ret);
                context.Response.Write(json);
            }
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}